<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>登入</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="admin登录">
    <script type="text/javascript" src="static/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="static/layui/layui.js"></script>
    <link rel="stylesheet" href="static/res/layui/css/layui.css">
    <link rel="stylesheet" href="static/res/css/global.css">
</head>
<body>

<jsp:include page="/admin/fly-head.jsp"></jsp:include>

<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user" style="text-align: center">
            <ul class="layui-tab-title" style="width: 200px;margin: 0 auto">
                <li class="layui-this">登入</li>
                <li><a href="AdminUserRegistration.jsp">注册</a></li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0; width: 309px;margin: 0 auto">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <form method="post">
                            <div class="layui-form-item">
                                <label for="L_username" class="layui-form-label">用户名</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_username" name="username" required lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="password" required lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_vercode" class="layui-form-label">验证码</label>
                                <div class="layui-input-inline" style="width: 90px">
                                    <input type="text" id="L_vercode" name="vercode" required lay-verify="required"
                                           placeholder="验证码" autocomplete="off" class="layui-input" style="width: 90px">

                                    <div class="layui-form-mid">
                                    </div>
                                </div>
                                <div>
                                    <!-- 验证码 -->
                                    <img id="img" style="float: left" src="${ctx}/authImage"/>
                                    <a href='#' onclick="javascript:changeImg()" style="color:white;">
                                        <label style="color:black;float: right">换一张</label></a>
                                </div>


                                <div class="layui-form-item" style="width: 200px;margin: 0 auto">
                                    <button id="L_login" class="layui-btn" lay-filter="*" lay-submit
                                            onclick="login();return false">立即登录
                                    </button>
                                    <span style="padding-left:20px;">
                                   <a href="/userAdmin/AdminForget">忘记密码？</a>
                                </span>
                                </div>
                                <div class="layui-form-item fly-form-app" style="width: 230px;margin: 0 auto">
                                    <span>或者使用社交账号登入</span>
                                    <a href="" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})"
                                       class="iconfont icon-qq" title="QQ登入"></a>
                                    <a href="" onclick="layer.msg('正在通过微博登入', {icon:16, shade: 0.1, time:0})"
                                       class="iconfont icon-weibo" title="微博登入"></a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

  <jsp:include page="/admin/fly-footer.jsp"></jsp:include>

</div>


<script src="static/res/layui/layui.js"></script>
<!-- 触发JS刷新-->
<script type="text/javascript">
    function changeImg() {
        var img = document.getElementById("img");
        img.src = "${ctx}/authImage?date=" + new Date();
        ;
    }

    function login() {

        if ($("#L_username").val() == "") {
            alert("用户名不能为空");
            $("#L_username").focus();
            return false;
        }
        if ($("#L_pass").val() == "") {
            alert("密码不能为空");
            $("#L_pass").focus();
            return false;
        }
        if ($("#L_vercode").val() == "") {
            alert("验证码不能为空");
            $("#L_vercode").focus();
            return false;
        }
//获取用户名密码 验证码
        var username = document.getElementById("L_username").value;
        var password = document.getElementById("L_pass").value;
        var vercode = document.getElementById("L_vercode").value.toLowerCase();
        $.ajax({
            url: "/userAdmin/login",
            type: "post",
            datatype: "json",
            data: {
                'username': username,
                'password': password,
                'vercode': vercode
            },
            success: function (data, state) {
                 if(data.msg=="登录成功"){
                     window.location.href="/AdminUserBackground.jsp";
                 }else if(data.msg=="用户名或密码不正确"){
                     alert("用户名或密码不正确");
                     changeImg();
                 }else if (data.msg=="验证码不正确"){
                     alert("验证码不正确");
                     changeImg();
                 }else if (data.msg=="账号未通过审核请联系管理员"){
                     alert("账号未通过审核，请联系管理员");
                 }


            },
            error: function () {
                alert("登录出错，请重新登录");
                changeImg();
            }
        })
    }


</script>

</body>
</html>